/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pratica7;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author diego
 */
public class Pratica7 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // Grafo 1:
        HashMap<AbstractMap.SimpleEntry<Vertice, Vertice>, Peso> weights = new HashMap<>();
        ArrayList<Vertice> vertices = new ArrayList<>();

        vertices.add(new Vertice("1"));
        vertices.add(new Vertice("2"));
        vertices.add(new Vertice("3"));
        vertices.add(new Vertice("4"));
        vertices.add(new Vertice("5"));
        
        JGrafo g = new JGrafo(vertices);
        
        // Adjacencias 1
        g.add_edge(vertices.get(0), vertices.get(1));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(0), vertices.get(1)), new Peso(3, 8));
        g.add_edge(vertices.get(0), vertices.get(2));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(0), vertices.get(2)), new Peso(10, 4));
        g.add_edge(vertices.get(0), vertices.get(3));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(0), vertices.get(3)), new Peso(2, 5));
        
        // Adjacencias 2
        g.add_edge(vertices.get(1), vertices.get(4));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(4)), new Peso(5, 9));
        
        // Adjacencias 3
        g.add_edge(vertices.get(2), vertices.get(3));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(2), vertices.get(3)), new Peso(4, 1));
        
        // Adjacencias 4
        g.add_edge(vertices.get(3), vertices.get(2));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(2)), new Peso(7, 5));
        g.add_edge(vertices.get(3), vertices.get(1));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(1)), new Peso(8, 3));
        g.add_edge(vertices.get(3), vertices.get(0));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(0)), new Peso(7, 2));
        
        System.out.println("Menor caminho usando dijkstra entre a origem e o destino no grafo 1:");
        String path = "";
        HashMap<Vertice, ArrayList<Vertice>> result_set = Dijkstra.dijkstra(g, weights, vertices.get(0));
        for (int i = (result_set.get(vertices.get(4)).size() - 1); i >= 0; i --) {
            path += result_set.get(vertices.get(4)).get(i).name + ", ";
        }
        System.out.println(path);
        System.out.println("Custo: "+vertices.get(4).key);
        
        // Grafo 2:
        weights = new HashMap<>();
        vertices = new ArrayList<>();

        vertices.add(new Vertice("a"));
        vertices.add(new Vertice("b"));
        vertices.add(new Vertice("c"));
        vertices.add(new Vertice("d"));
        vertices.add(new Vertice("e"));
        
        g = new JGrafo(vertices);
        
        // Adjacencias a
        g.add_edge(vertices.get(0), vertices.get(1));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(0), vertices.get(1)), new Peso(3, 3));
        g.add_edge(vertices.get(0), vertices.get(3));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(0), vertices.get(3)), new Peso(5, 5));
        
        // Adjacencias b
        g.add_edge(vertices.get(1), vertices.get(2));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(2)), new Peso(6, 2));
        g.add_edge(vertices.get(1), vertices.get(3));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(1), vertices.get(3)), new Peso(2, 2));
        
        // Adjacencias c
        g.add_edge(vertices.get(2), vertices.get(4));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(2), vertices.get(4)), new Peso(2, 2));
        
        // Adjacencias d
        g.add_edge(vertices.get(3), vertices.get(2));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(2)), new Peso(4, 5));
        g.add_edge(vertices.get(3), vertices.get(1));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(1)), new Peso(1, 3));
        g.add_edge(vertices.get(3), vertices.get(4));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(3), vertices.get(4)), new Peso(6, 9));
        
        // Adjacencias e
        g.add_edge(vertices.get(4), vertices.get(2));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(4), vertices.get(2)), new Peso(7, 4));
        g.add_edge(vertices.get(4), vertices.get(0));
        weights.put(new AbstractMap.SimpleEntry<>(vertices.get(4), vertices.get(0)), new Peso(3, 6));
        
        System.out.println("Menor caminho usando dijkstra entre a origem e o destino no grafo 2:");
        path = "";
        result_set = Dijkstra.dijkstra(g, weights, vertices.get(3));
        for (int i = (result_set.get(vertices.get(0)).size() - 1); i >= 0; i --) {
            path += result_set.get(vertices.get(0)).get(i).name + ", ";
        }
        System.out.println(path);
        System.out.println("Custo: "+vertices.get(0).key);
    }

}
